home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 52
/
Amiga Format AFCD52 (Issue 136, May 2000).iso
/
-in_the_mag-
/
reader_requests
/
xgtool
/
xgtoolset
/
source
/
hextransmitter
/
hextransmitter.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-02-23
|
10KB
|
471 lines
/*
HXTM: A Bars and Pipes tool simple transmitting MIDI-Hex
© 1998 Alfred Faust
The code was written to compile it with the free GNU-C-compiler of the
ADE. Look at the part , that place the imagedate in chip-RAM. The
GNU-C-compiler hasn't as yet a keyword like DICE or other compiler for
handle this easy.
This code is released into the Public Domain, and may be freely
distributed in its original form.
It is supplied ``as is'', and comes with no warranty. This program code
was released because it might be useful as a starting point for other
programmers. However, if any damage arises from its use, the original
author will not be held liable.
You are free to use and modify this code to your heart's content,
provided you acknowledge me as the original author in any code that you
might distribute which is based largely on this code.
I acknowledge that the design of this tool is influenced strongly by
the example code supplied with the Rules for Tools package. However, I
have made substantial contributions of my own.
Alfred Faust
J.K.Dax@t-online.de
History:
1.0 (8.11.98)
Initial Release.
*/
#include "bars.h"
#include <libraries/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <exec/exec.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <string.h>
#include <intuition/intuition.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define HXTM_NAME "Hex-Transmitter"
#define HXTM_ID 0x4858542F
#define HXTM_TYPE (TOOL_NORMAL | TOOL_NOTPAD)
#define HXSTR_GADGET 1
extern struct ExecBase * SysBase;
UWORD *HXTM=NULL;
static char sysexbuffer[50]={'f', '0', 'f', '7'};
static char sysexundobuffer[50]={'f', '0', 'f', '7'};
static UWORD HXTMdata[] =
{
/* Plane 0 */
0x7FFF,0xFE00,
0x4000,0x0200,
0x4F42,0xEA00,
0x4F5E,0xEA00,
0x4F5F,0x5A00,
0x4043,0xBA00,
0x4F5F,0x5A00,
0x4F5F,0x5A00,
0x4F5E,0xEA00,
0x4F42,0xEA00,
0x4000,0x0200,
0x7FFF,0xFE00,
/* Plane 1 */
0x0000,0x0200,
0x3FFF,0xFE00,
0x37BD,0x7600,
0x37AF,0x7600,
0xB7AF,0xAF00,
0xBFBD,0xDF00,
0xB7AF,0xAF00,
0xB7AF,0xAF00,
0x37AF,0x7600,
0x37BD,0x7600,
0x3FFF,0xFE00,
0x3FFF,0xFE00,
/* Plane 2 */
0x0000,0x0000,
0x0000,0x0000,
0x1FFF,0xF800,
0x1FFF,0xF800,
0x1FFF,0xF800,
0x1FFF,0xF800,
0x1FFF,0xF800,
0x1FFF,0xF800,
0x1FFF,0xF800,
0x1FFF,0xF800,
0x0000,0x0000,
0x0000,0x0000
};
static struct Image HXTM_image = {
0,0,
24 , 12 , 3 ,
NULL,
0x1f,0x00,
NULL
};
struct HXTMTool
{
struct Tool tool;
ULONG HX;
};
static struct ToolMaster master;
extern struct Functions *functions;
static void HXTM_tool_init(struct HXTMTool *tool)
{
tool->tool.touched = TOUCH_INIT;
tool->HX = 0;
}
static struct Event * __saveds processeventcode(struct Event *event)
{
event->tool = event->tool->next;
return(event);
}
/* HXSTR_GADGET gadget. */
/* Border for the HXSTR_GADGET */
static SHORT HXSTRvectors4[] = { //black
-4,11,
-4,-4,
247,-4
};
static struct Border HXSTRBorder4 = {
0,0,
1,0,JAM1,
3,
HXSTRvectors4,
NULL
};
static SHORT HXSTRvectors3[] = { //black
-4,11,
247,11,
247,-4
};
static struct Border HXSTRBorder3 = {
0,0,
1,0,JAM1,
3,
HXSTRvectors3,
&HXSTRBorder4
};
static SHORT HXSTRvectors2[] = { //white
-5,11,
-5,-5,
247,-5
};
static struct Border HXSTRBorder2 = {
0,0,
2,0,JAM1,
3,
HXSTRvectors2,
&HXSTRBorder3
};
static SHORT HXSTRvectors1[] = { //white
-3,10,
246,10,
246,-3
};
static struct Border HXSTRBorder1 = {
0,0,
2,0,JAM1,
3,
HXSTRvectors1,
&HXSTRBorder2
};
/* stringgadget */
static char sysexbuffer[50];
static char sysexundobuffer[50];
static struct IntuiText HXSTRText = {
1,0,JAM1,
-80,-1,
NULL,
"MIDI-Hex:",
NULL
};
static struct StringInfo HXSTRStringinfo = {
sysexbuffer,
sysexundobuffer,
0, 50, 0,
0, 0, 0,
0, 0,
NULL,
NULL,
NULL
};
static struct Gadget HXSTRGadget = {
NULL,
95,25,
240,8,
GADGHCOMP,
RELVERIFY,
STRGADGET,
(APTR)&HXSTRBorder1,
NULL,
&HXSTRText,
NULL,
(APTR)&HXSTRStringinfo,
HXSTR_GADGET,
NULL
};
struct NewWindow HXTMNewWindowStructure1 = {
75,85,
370, 50,
0,6,
GADGETDOWN+GADGETUP+CLOSEWINDOW,
WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH,
&HXSTRGadget,
NULL,
"HXTM-Transmitter V 1.0",
NULL,
NULL,
5,5,
-1,-1,
CUSTOMSCREEN
};
static void __saveds send_note(struct HXTMTool *tool, const LONG time, const UBYTE note)
{
struct NoteEvent *on_event = (struct NoteEvent *)(*functions->allocevent)();
if (on_event)
{
struct NoteEvent *off_event = (struct NoteEvent *)(*functions->allocevent)();
if (off_event)
{
on_event->next = NULL;
on_event->type = EVENT_VOICE;
on_event->status = MIDI_NOTEON;
on_event->value = note;
on_event->velocity = 127;
on_event->time = time;
on_event->tool = tool->tool.next;
(*functions->qevent)(on_event);
off_event->next = NULL;
off_event->type = EVENT_VOICE;
off_event->status = MIDI_NOTEOFF;
off_event->value = note;
off_event->time = time + 100;
off_event->tool = tool->tool.next;
(*functions->qevent)(off_event);
}
else
{
(*functions->freeevent)(on_event);
}
}
}
static void __saveds sendsysex(char *buff, short size, struct HXTMTool *tool, const LONG time)
{
struct StringEvent *event;
struct String *string;
event = (struct StringEvent *) (*functions->allocevent)();
if (event)
{
string = (struct String *) (*functions->myalloc)(size + 3,MEMF_CLEAR);
if (string)
{
event->string = string;
memcpy(string->string, buff, size);
string->length = size + 2;
event->type = EVENT_SYSX;
event->status = MIDI_SYSX;
event->time = time;
event->tool = tool->tool.next;
WaitTOF();
(*functions->qevent)(event);
(*functions->myfree)(string);
}
}
}
static void __saveds trans_hx(struct HXTMTool *tool, const LONG time)
{
LONG size;
int a, b, x, y ;
UBYTE abuf[32];
char chr[4];
char *zbuf = NULL;
struct Event *sysx_event;
//translate sysexbuffer into hex
size = strlen(sysexbuffer);
zbuf = (char *)AllocVec(size+2, MEMF_ANY|MEMF_CLEAR);
if(zbuf)
{
CopyMem(&sysexbuffer, zbuf, size);
b=0;
for(a=0;a < size;a=a+2)
{
chr[0] = zbuf[a];
chr[1] = zbuf[a+1];
x=(isdigit((int)chr[0]))? (chr[0]&0xF) : ((chr[0]&0xDF)-55); //this is the
y=(isdigit((int)chr[1]))? (chr[1]&0xF) : ((chr[1]&0xDF)-55); //the translate-core
abuf[b++] = ((x<<4)|y); //writing with bitmanipulation
}
//send hexdata
FreeVec(zbuf);
sendsysex(abuf, b, tool, time);
}
}
static void __saveds edittoolcode(struct HXTMTool *tool)
{
struct IntuiMessage *message;
struct Window *window;
LONG class, code;
struct Gadget *gadget;
struct NewWindow *newwindow;
LONG time;
HXTMNewWindowStructure1.Screen = functions->screen;
if (tool->tool.touched & TOUCH_EDIT)
{
HXTMNewWindowStructure1.LeftEdge = tool->tool.left;
HXTMNewWindowStructure1.TopEdge = tool->tool.top;
HXTMNewWindowStructure1.Width = tool->tool.width;
HXTMNewWindowStructure1.Height = tool->tool.height;
}
if (!tool->tool.touched)
{
HXTM_tool_init(tool);
}
newwindow = (struct NewWindow *) (*functions->DupeNewWindow)(&HXTMNewWindowStructure1);
if (!newwindow)
{
return;
}
newwindow->Title = 0;
newwindow->Flags |= BORDERLESS;
newwindow->Flags &= ~0xF;
newwindow->BlockPen = 0;
newwindow->DetailPen = 0;
window = (struct Window *) (*functions->FlashyOpenWindow)(newwindow);
if (!window)
{
return;
}
tool->tool.window = window;
(*functions->EmbossWindowOn)(window,WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG, HXTM_NAME,(short)-1,(short)-1,0,0);
for (;;)
{
ActivateGadget(&HXSTRGadget, window, NULL);
message = (struct IntuiMessage *) (*functions->GetIntuiMessage)(window);
class = message->Class;
code = message->Code;
gadget = (struct Gadget *) message->IAddress;
class = (*functions->SystemGadgets)(window,class,gadget,code);
ReplyMsg((struct Message *)message);
if (class == CLOSEWINDOW) break;
else if (class == GADGETUP)
{
const short id = gadget->GadgetID;
switch (id)
{
case HXSTR_GADGET:
{
time = functions->timenow;
trans_hx(tool, time);
break;
}
}
send_note(tool, time + 200, 60);
}
else if (class == GADGETDOWN)
{
}
}
tool->tool.window = 0;
tool->tool.left = window->LeftEdge;
tool->tool.top = window->TopEdge;
tool->tool.width = window->Width;
tool->tool.height = window->Height;
tool->tool.touched = TOUCH_INIT | TOUCH_EDIT;
(*functions->EmbossWindowOff)(window);
(*functions->FlashyCloseWindow)(window);
(*functions->DeleteNewWindow)(newwindow);
}
//to leave the tool correct
void __saveds removetool()
{
FreeVec(HXTM);
}
struct ToolMaster * inittoolmaster()
{
if (!(HXTM=(UWORD *)AllocVec(sizeof (HXTMdata),MEMF_CHIP|MEMF_CLEAR))) return(NULL);
CopyMem(&HXTMdata,HXTM, sizeof (HXTMdata));
HXTM_image.ImageData = HXTM;
memset((char *)&master,0,sizeof(struct ToolMaster));
master.toolid = HXTM_ID;
master.image = &HXTM_image;
strcpy(master.name, HXTM_NAME);
master.edittool = edittoolcode;
master.processevent = processeventcode;
master.tooltype = HXTM_TYPE;
master.toolsize = sizeof(struct HXTMTool);
master.removetool = removetool;
return(&master);
}